-- bine_level_up
-- create by cheny3
-- 魔藤学习/升级

-- 主动技
local skills = {6001, 6011, 6021, 6031};

return {
    -- 判断
    canTrigger = function(args)
        local bine = ME.user.bine;
        if not bine then
            return false;
        end

        local classId = bine.classId;
        if BineM.query(classId, "alias") ~= "magic_bine" then
            -- 不是魔藤
            return false;
        end

        local bineSkills = bine:getSkills();

        -- 判断能否学习/升级主动技
        for _, skillId in pairs(skills) do
            if BineM.canLearnSkill(skillId) == true then
                return true;
            end
        end
        for _, skillId in pairs(bineSkills) do
            if BineM.canUpgradeSkill(skillId) == true then
                return true;
            end
        end

        if BineM.canLevelUp() == true then
            -- 可以升级
            return true;
        end

        return false;
    end,

    -- 触发
    trigger = function(args)
        local bine = ME.user.bine;
        if not bine then
            return false;
        end

        local bineSkills = bine:getSkills();
        -- 判断能否学习/升级主动技
        for _, skillId in pairs(skills) do
            if BineM.canLearnSkill(skillId) == true then
                return DungeonActionM.go("bine_learn_skill", 0, skillId);
            end
        end

        for _, skillId in pairs(bineSkills) do
            if BineM.canUpgradeSkill(skillId) == true then
                return DungeonActionM.go("bine_upgrade_skill", 0, skillId);
            end
        end

        -- 尝试升级
        if BineM.canLevelUp() == true then
            return DungeonActionM.go("bine_level_up");
        end

        return false;
    end,
};
